package com.usian.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.usian.common.R;
import com.usian.pojo.Goods;
import com.usian.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    /**
     * 查询
     *
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public R findPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "5") Integer pageSize,String name) {
        Page<Goods> page1 = goodsService.findPage(page, pageSize,name);
        return R.success(page1);
    }

    /**
     * 添加
     * @param goods
     * @return
     */
    @PostMapping
    public R add(@RequestBody Goods goods){
        return goodsService.add(goods);
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @DeleteMapping
    public R delete(String ids){
        return goodsService.delete(ids);
    }

    /**
     * 修改
     * @param goods
     * @return
     */
    @PutMapping
    public R edit(@RequestBody Goods goods){
        return goodsService.edit(goods);
    }

    /**
     * 启用-禁用
     * @param ids
     * @param status
     * @return
     */
    @PostMapping("status/{status}")
    public R editStatus1(String ids,@PathVariable Integer status){
        return goodsService.editStatus(ids,status);
    }

    /**
     * 提交-未提交
     * @param ids
     * @param status
     * @return
     */
    @GetMapping("status/{status}")
    public R editStatus2(String ids,@PathVariable Integer status){
        return goodsService.editStatus2(ids,status);
    }

    /**
     * 上架-下架
     * @param ids
     * @param status
     * @return
     */
    @PutMapping("status/{status}")
    public R editStatus3(String ids,@PathVariable Integer status){
        return goodsService.editStatus3(ids,status);
    }

    /**
     * 回显
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public R toEdit(@PathVariable Integer id){
        return goodsService.toEdit(id);
    }
}








